// ./config/webpack.dev.js
const merge = require('webpack-merge');
const common = require('./webpack.base.js');

const path = require('path');
// 加载插件
const webpack = require('webpack');
const hotMiddlewareScript = 'webpack-hot-middleware/client?quiet=true'; // &reload=true 未使用accept重载的，使用reload重载
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');

function joinPath(filepath) {
    return path.join(__dirname, filepath);
}

module.exports = merge(common, {
    mode: 'development',
    devtool: 'cheap-module-eval-source-map',
    entry: {
        main: [hotMiddlewareScript, joinPath('../src/main.js')],
    },
    output: {
        filename: '[name].js?v=[hash]', // HMR不能使用chunkhash和contenthash
        chunkFilename: '[id].js?v=[hash]' // HMR不能使用chunkhash和contenthash
    },
    plugins: [
        new FriendlyErrorsWebpackPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ]
});
